# -*- encoding:utf-8 -*-
import sys
from dingtalkchatbot.chatbot import DingtalkChatbot

def send_message():
    """
    发送钉钉消息，检查发送消息格式/是否@所有人是否是bool值
    :return:
    """
    prom_list = sys.argv
    dingding_bot_token = prom_list[1]
    send_meg = prom_list[2]
    is_at_all_bool_str = prom_list[3]

    if "g" not in send_meg:
        print("发送消息请带g关键字，否则无法发送，请重新构建发送消息")
        exit(0)

    if bool(is_at_all_bool_str) != True | False:
        print("请填写标准 True 或者 False")
        exit(0)

    webhook = 'https://oapi.dingtalk.com/robot/send?access_token=%s' % (dingding_bot_token)
    # secret = 'SEC11b9...这里填写自己的加密设置密钥' # 可选：创建机器人勾选“加签”选项时使用

    # 初始化bot
    bot = DingtalkChatbot(webhook)

    # Text消息
    bot.send_text(msg="%s" % (send_meg), is_at_all=is_at_all_bool_str)

if __name__ == '__main__':
    send_message()
